#!/usr/bin/env bash


now(){
    echo "$(date '+%Y-%m-%d %H:%M:%S')";
}

mk_dir(){
    local dir=$1
    if [ -d "$1" ];then
        return 0;
    else
        mkdir -p $1
        return $?
    fi
}

# arg1 file path
# arg2 msg
# arg2 alarm level
log (){
    local msg=""
    if   [ $3 -eq 0 ]; then
        msg="[ Info ] "
    elif [ $3 -eq 1 ]; then
        msg="[ Alarm ] "
    elif [ $3 -eq 2 ]; then
        msg="[ Error ] "
    else
        :
    fi
    msg="${msg} $(date '+%Y-%m-%d %H:%M:%S') $2"
    echo "${msg}" >> "$1"
}

compare_file (){
	local file1="$1"
	local file2="$2"
	if [ ! -f "${file1}" ] || [ ! -f "${file2}" ]; then
	    echo "文件不存在或不是一个普通文件"
	    return 1
	fi
	local file_type=$(file --mime-type -b "${file1}")
	case "$file_type" in
		# 执行文本文件的操作
	    text/*)
			diff "$1" "$2"
			return $?
			;;
		# 执行 ZIP 文件的操作
	    application/zip)
			zipcmp "$1" "$2"
			return $?
			;;
		*)
			return 1
			#echo "未知文件类型: $file_type"
			;;
	esac				
}

